home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / bmppaint.zip / BMPPAINT.PAS < prev    next >
Pascal/Delphi Source File  |  1993-04-14  |  3KB  |  102 lines

  1. {************************************************
  2.   The Bitmaps are loaded in SetUpWindow, it is shown
  3.   in Paint and in WmLButtonDown, and it is destroyed
  4.   in the Done procedure.
  5.   There are two different methods of showing a bitmap
  6.   in this example. The first displays it to the screen
  7.   with the Paint method, the second in WmLButtonDown.
  8.   To use the second method, just click on the screen
  9.   with the left button.
  10. ************************************************}
  11.  
  12. program MyProgram;
  13.  
  14. uses WinTypes, WinProcs, OWindows, Strings;
  15.  
  16. {$R BmpPaint}
  17.  
  18. type
  19.   TMyApplication = object(TApplication)
  20.     procedure InitMainWindow; virtual;
  21.   end;
  22.  
  23. type
  24.   PMyWindow = ^TMyWindow;
  25.   TMyWindow = object(TWindow)
  26.       Foo1: HBitmap;
  27.       Foo2: HBitmap;
  28.     destructor Done; virtual;
  29.     procedure SetUpWindow; virtual;
  30.     procedure Paint(PaintDC: HDC; var PaintInfo: TPaintStruct); virtual;
  31.     procedure WmLButtonDown(var Msg: TMessage);
  32.       virtual wm_First + wm_LButtonDown;
  33.   end;
  34.  
  35. {--------------------------------------------------}
  36. { TMyWindow's method implementations:              }
  37. {--------------------------------------------------}
  38.  
  39. destructor TMyWindow.Done;
  40. begin
  41.   DeleteObject(Foo1);
  42.   DeleteObject(Foo2);
  43.   inherited Done;
  44. end;
  45.  
  46. procedure TMyWindow.SetUpWindow;
  47. begin
  48.   inherited SetUpWindow;
  49.   Foo1 := LoadBitMap(HInstance, 'Foo1');
  50.   Foo2 := LoadBitMap(HInstance, 'Foo2');
  51. end;
  52.  
  53. procedure TMyWindow.Paint(PaintDC: HDC; var PaintInfo: TPaintStruct);
  54. var
  55.   OldBitmap: HBitmap;
  56.   MemDC: HDC;
  57. begin
  58.   MemDC := CreateCompatibleDC(PaintDC);
  59.   OldBitmap := SelectObject(MemDC, Foo1);
  60.   BitBlt(PaintDC, 10, 10, 64, 64, MemDC, 0, 0, SRCCopy);
  61.   SelectObject(MemDC, OldBitmap);
  62.   DeleteObject(MemDC);
  63. end;
  64.  
  65. procedure TMyWindow.WmLButtonDown;
  66. var
  67.   PaintDC: HDC;
  68.   MemDC: HDC;
  69.   OldBitMap: HBitMap;
  70. begin
  71.   PaintDC := GetDC(HWindow);
  72.   MemDC := CreateCompatibleDC(PaintDC);
  73.   OldBitmap := SelectObject(MemDC, Foo2);
  74.   BitBlt(PaintDC, 100, 10, 64, 64, MemDC, 0, 0, SRCCopy);
  75.   SelectObject(MemDC, OldBitmap);
  76.   DeleteObject(MemDC);
  77.   ReleaseDC(HWindow, PaintDC);
  78. end;
  79.  
  80.  
  81. {--------------------------------------------------}
  82. { TMyApplication's method implementations:         }
  83. {--------------------------------------------------}
  84.  
  85. procedure TMyApplication.InitMainWindow;
  86. begin
  87.   MainWindow := New(PMyWindow, Init(nil, 'Sample ObjectWindows Program'));
  88. end;
  89.  
  90. {--------------------------------------------------}
  91. { Main program:                                    }
  92. {--------------------------------------------------}
  93.  
  94. var
  95.   MyApp: TMyApplication;
  96.  
  97. begin
  98.   MyApp.Init('MyProgram');
  99.   MyApp.Run;
  100.   MyApp.Done;
  101. end.
  102.